home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / kcl.lha / c / unixint.c < prev    next >
C/C++ Source or Header  |  1987-06-04  |  2KB  |  109 lines

  1. /*
  2. (c) Copyright Taiichi Yuasa and Masami Hagiya, 1984.  All rights reserved.
  3. Copying of this file is authorized to users who have executed the true and
  4. proper "License Agreement for Kyoto Common LISP" with SIGLISP.
  5. */
  6.  
  7. /*
  8.     unixint.c
  9. */
  10.  
  11. #include "include.h"
  12. #include <signal.h>
  13.  
  14. object SVinterrupt_enable;
  15.  
  16. sigalrm()
  17. {
  18.     if (interrupt_flag) {
  19.         interrupt_flag = FALSE;
  20.         terminal_interrupt(TRUE);
  21.     }
  22. }
  23.  
  24. sigint()
  25. {
  26.     if (!interrupt_enable || interrupt_flag) {
  27. /*
  28.         if (!interrupt_enable)
  29.             fprintf(stderr, "\nInterrupt ignored.\n");
  30. */
  31.         signal(SIGINT, sigint);
  32.         return;
  33.     }
  34.     if (symbol_value(SVinterrupt_enable) == Cnil) {
  35.         SVinterrupt_enable->s.s_dbind = Ct;
  36.         signal(SIGINT, sigint);
  37.         return;
  38.     }
  39.     interrupt_flag = TRUE;
  40.     signal(SIGALRM, sigalrm);
  41.     alarm(1);
  42.     signal(SIGINT, sigint);
  43. }
  44.  
  45. sigfpe()
  46. {
  47.     signal(SIGFPE, sigfpe);
  48.     FEerror("Floating-point exception.", 0);
  49. }
  50.  
  51. #ifdef BSD
  52. signal_catcher(sig, code, scp)
  53. {
  54.     char str[64];
  55.  
  56.     if (!interrupt_enable) {
  57.         sprintf(str, "signal %d caught (during GBC)", sig);
  58.         error(str);
  59.     } else {
  60.         vs_push(make_fixnum(sig));
  61.         FEerror("Signal ~D caught.~%\
  62. The internal memory may be broken.~%\
  63. You should check the signal and exit from Lisp.", 1, vs_head);
  64.     }
  65. }
  66.  
  67. siLcatch_bad_signals()
  68. {
  69.     check_arg(0);
  70.  
  71.     signal(SIGILL, signal_catcher);
  72.     signal(SIGIOT, signal_catcher);
  73.     signal(SIGEMT, signal_catcher);
  74.     signal(SIGBUS, signal_catcher);
  75.     signal(SIGSEGV, signal_catcher);
  76.     signal(SIGSYS, signal_catcher);
  77.     vs_push(Ct);
  78. }
  79.  
  80. siLuncatch_bad_signals()
  81. {
  82.     check_arg(0);
  83.  
  84.     signal(SIGILL, SIG_DFL);
  85.     signal(SIGIOT, SIG_DFL);
  86.     signal(SIGEMT, SIG_DFL);
  87.     signal(SIGBUS, SIG_DFL);
  88.     signal(SIGSEGV, SIG_DFL);
  89.     signal(SIGSYS, SIG_DFL);
  90.     vs_push(Ct);
  91. }
  92. #endif
  93.  
  94. init_interrupt()
  95. {
  96.     signal(SIGFPE, sigfpe);
  97.     signal(SIGINT, sigint);
  98. }
  99.  
  100. init_interrupt1()
  101. {
  102.     SVinterrupt_enable
  103.     = make_si_special("*INTERRUPT-ENABLE*", Ct);
  104. #ifdef BSD
  105.     make_si_function("CATCH-BAD-SIGNALS", siLcatch_bad_signals);
  106.     make_si_function("UNCATCH-BAD-SIGNALS", siLuncatch_bad_signals);
  107. #endif
  108. }
  109.